<style>
    input[type=text] {
        line-height: 28px;
        outline: none;
        color: #333;
        width: 100px;
        padding: 0 10px;
    }
</style>
<div class="layui-form" id="popup" lay-filter="layuiadmin-form-user">

    <table class="layui-table" style="min-height: 415px;">
        <colgroup>
            <!-- <col width="150">
          <col width="200">
          <col> -->
        </colgroup>
        <thead>
            <tr>
                <th></th>
                <th style="font-weight: 600;text-align: center;">按钮开关</th>
                <th style="font-weight: 600;text-align: center;">时间间隔</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td>1</td>
                <td><input type="checkbox" value="1" name="line-1" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer1}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer1" name="dwauploadtimer1" placeholder="请输入模块1的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>2</td>
                <td><input type="checkbox" value="2" name="line-2" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer2}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer2" name="dwauploadtimer2" placeholder="请输入模块2的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>3</td>
                <td><input type="checkbox" value="3" name="line-3" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer3}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer3" name="dwauploadtimer3" placeholder="请输入模块3的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>4</td>
                <td><input type="checkbox" value="4" name="line-4" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer4}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer4" name="dwauploadtimer4" placeholder="请输入模块4的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>5</td>
                <td><input type="checkbox" value="5" name="line-5" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer5}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer5" name="dwauploadtimer5" placeholder="请输入模块5的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>6</td>
                <td><input type="checkbox" value="6" name="line-6" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer6}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer6" name="dwauploadtimer6" placeholder="请输入模块6的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>7</td>
                <td><input type="checkbox" value="7" name="line-7" lay-skin="switch" lay-filter="switchTest"></td>
                <!-- <td>{{list.dwauploadtimer7}}ms</td> -->
                <td><input type="text" :value="list.dwauploadtimer7" name="dwauploadtimer7" placeholder="请输入模块7的时间间隔" lay-skin="input"> ms</td>

            </tr>
            <tr>
                <td>8</td>
                <!-- lay-text="开启|关闭" -->
                <td><input type="checkbox" value="8" name="line-8" lay-skin="switch" lay-filter="switchTest"></td>
                <td><input type="text" :value="list.dwauploadtimer8" name="dwauploadtimer8" placeholder="请输入模块8的时间间隔" lay-skin="input"> ms</td>
                <!-- <td>{{list.dwauploadtimer8}}ms</td> -->
            </tr>
        </tbody>
    </table>
    <div class="one">
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-user-back-now-submit" value="保存" class="layui-btn" id="nowSave" :data-time="startTime">
        </div>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-user-back-submit" value="立即生效" class="layui-btn">
        </div>

    </div>
    <!-- <div class="layui-form-item">
    
    </div> -->
</div>
<script src="/start/vue.js"></script>

<style>
    .layui-layer-admin .layui-layer-content {
        padding: 0 20px;
        line-height: 22px;
    }
    
    .one {
        width: 100%;
        text-align: center;
        margin-top: 5%;
    }
</style>
<!-- <script src="/start/layui/layui.js"></script> -->
<script>
    layui.use(['admin', 'form', 'upload'], function(data) {
        var form = layui.form;
        var $ = layui.$,
            setter = layui.setter,
            form = layui.form,
            admin = layui.admin,
            upload = layui.upload;

        console.log('dddd', data)
        upload.render({
            elem: '#layuiadmin-upload-useradmin',
            url: setter.request.baseUrl + '/upload/uploadImg',
            accept: 'images',
            method: 'get',
            acceptMime: 'image/*',
            before: function(obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            },
            done: function(res) {
                layer.closeAll('loading'); //关闭loading
                $(this.item).prev("div").children("input").val(res.path)
                $("#img-intsance").attr("src", res.path);
            }
        });
        new Vue({
            el: '#popup',
            data: {
                list: {
                    dwauploadtimer1: 0,
                    dwauploadtimer2: 0,
                    dwauploadtimer3: 0,
                    dwauploadtimer4: 0,
                    dwauploadtimer5: 0,
                    dwauploadtimer6: 0,
                    dwauploadtimer7: 0,
                    dwauploadtimer8: 0,
                    uauploadenable1: 0,
                    uauploadenable2: 0,
                    uauploadenable3: 0,
                    uauploadenable4: 0,
                    uauploadenable5: 0,
                    uauploadenable6: 0,
                    uauploadenable7: 0,
                    uauploadenable8: 0,
                },
                startTime: '',
                agvid: 1

            },
            created() {
                var that = this
                var sSeach = window.location.href.split(',')[1];
                if (sSeach >= 0) {
                    console.log('sSeach', sSeach)
                    that.agvid = sSeach * 1
                } else {
                    that.agvid = 1
                }
                console.log("form", that.agvid)
                admin.req({
                    url: setter.request.baseUrl + "agv-config/query",
                    data: JSON.stringify({
                        'agvId': that.agvid,

                    }),
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    done: function(res) {

                        if (res.info) {

                            that.list = res.info[0]

                        }
                        $("input[type='checkbox']").each(function(index) {

                            if (that.list['uauploadenable' + (index + 1)]) {
                                // this.nextSibling.classList.add("layui-form-onswitch")
                                $(this).attr("checked", true)

                            }

                        })
                        form.render('checkbox');
                    },

                });
                //         form.on('switch(switchTest)', function(data){
                //             console.log(data.value)
                //             var num=data.value
                //             var nowTime= Date.parse(new Date())
                //             that.list['dwauploadtimer'+num]=nowTime-that.startTime

                //    if(this.checked){
                //     that.list['uauploadenable'+num]=1
                //    }else{
                //     that.list['uauploadenable'+num]=0
                //    }
                //    //do some ajax opeartiopns;
                //   });

                $('#nowSave').on('click', function() {
                    console.log('shjjakkkkkkkkk')
                    let date = new Date();
                    let dateYear = date.getFullYear();
                    let dateMonth = date.getMonth() + 1;
                    let dateDate = date.getDate();
                    let dateHours = date.getHours();
                    let dateMinutes = date.getMinutes();
                    let dateSeconds = date.getSeconds();
                    // var field = Object.entries(data.field); //获取提交的字段
                    // //新增用户信息  
                    var nowTime = Date.parse(new Date())
                        // var startTime=data.elem.getAttribute("data-time")
                        // console.log(field)
                        // for(let i=0;i<8;i++){
                        // that.list['uauploadenable'+i]=0
                        // }
                        // for(let i=0;i<field.length;i++){
                        //     let num=field[i][0].split('-')[1]
                        //     that.list['dwauploadtimer'+num]=nowTime-startTime
                        //     that.list['uauploadenable'+num]=field[i][1]=='on'?1:0
                        // }

                    that.list.updatetime = dateYear + '-' + dateMonth + '-' + dateDate + ' ' + dateHours + ':' + dateMinutes + ':' + dateSeconds
                        // that.list.agvId=that.agvid
                        // that.list.ctrlId=that.ctrlId
                    admin.req({
                        url: setter.request.baseUrl + "agv-config/add",
                        data: JSON.stringify(that.list),
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json;charset=UTF-8",

                        done: function(res) {

                            layer.close(index); //执行关闭 
                            layer.msg(res.msg);

                        },

                    });
                })
            },
            method: {
                aaa() {
                    console.log('asa', e)
                }
            },

        })



    })
</script>